home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / ini10.zip / STRTRUNC.C < prev   
Text File  |  1986-09-15  |  1KB  |  66 lines

  1. /**
  2. * name        StrTrunc -- truncate a string based on a set of trailing chars
  3. *
  4. * synopsis    str = StrTrunc(str, sub);
  5. *
  6. *        char    *str,        original string being truncated
  7. *            *sub;        truncation-character string
  8. *
  9. * description    Removes each trailing character in "str" that is in "sub".
  10. *        The string length is shortened by replacement with a null char.
  11. *
  12. * logic     Obvious.
  13. *
  14. * returns    str = original string.
  15. *
  16. * modifies    External "CharASCII", temporarily.
  17. *
  18. * cautions    "str" and "sub" must be valid pointers.
  19. *
  20. * examples    Obvious.
  21. **/
  22.  
  23. #ifndef LINT_ARGS
  24. #define LINT_ARGS
  25. #endif
  26. //    #include <ffc/const.h>
  27. //    #include <ffc/string.h>
  28.  
  29. /***/
  30.  
  31. extern    char        *StrTrunc(str, sub)
  32.  
  33.     char        *str,
  34.             *sub;
  35. {
  36. register unsigned char    *s;
  37.  
  38. /*
  39. *    set up CharASCII
  40. */
  41.  
  42. s = (unsigned char *)sub;
  43. while (*s)
  44.     CharASCII[*s++] = Null;
  45.  
  46. /*
  47. *    truncate
  48. */
  49.  
  50. s = (unsigned char *)str;
  51. while (*s)
  52.     s++;
  53. while (!(*s = CharASCII[*s]) && s-- > str)
  54.     ;
  55.  
  56. /*
  57. *    re-set CharASCII
  58. */
  59.  
  60. s = (unsigned char *)sub;
  61. while (CharASCII[*s] = *s)
  62.     s++;
  63.  
  64. return (str);
  65. }
  66.